package com.rslai.base.tool.servertest.command;

import com.rslai.base.tool.servertest.context.Context;
import com.rslai.base.tool.servertest.intercept.InterceptorFactory;
import com.rslai.base.tool.servertest.response.Response;

import java.util.List;

public abstract class CompositeStepCommand extends StepCommand {
    protected List<StepCommand> children;
    InterceptorFactory interceptor = InterceptorFactory.getInstance();

    public CompositeStepCommand(List<StepCommand> children) {
        this.children = children;
    }

    public Response doExecute(Response param, Context context) throws Throwable {
        Response response = param;
        for (StepCommand child : this.children) {
            this.interceptor.doBefore(child, response, context);
            response = child.doExecute(response, context);
            this.interceptor.doAfter(child, response, context);
        }
        return response;
    }

    public List<StepCommand> getChildren() {
        return this.children;
    }
}
